<%@ page language="java" contentType="text/html; charset=UTF-8"  
    pageEncoding="UTF-8"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>用户注册</title>  
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
//请求json，输出是json
function requestJson(){
    var userName=$("#userName").val()
    var password=$("#password").val() 
    
    var jsonData = {  
            "userName" : userName,  
            "password" : password  
    };
    $.ajax({
        type:'post',
        url:'${pageContext.request.contextPath }/user/registJson',
        contentType:'application/json;charset=utf-8',//指定为json类型
        //数据格式是json串，商品信息
        data:JSON.stringify(jsonData),
        success:function(data){//返回json结果
            alert(data.userName);
        }       
    }); 
}
</script>
</head>  
<body>  
    <form  method="post">  
        <table border="1">  
            <tr>  
                <td>用户名</td>  
                <td><input id="userName" type="text" name="userName"></td>  
            </tr>  
            <tr>  
                <td>密码</td>  
                <td><input id="password" type="text" name="password"></td>  
            </tr>  
            <tr>  
                <td><input type="button" value="注册" onclick="requestJson()"></td>  
            </tr>  
        </table>  
    </form>  
</body>  
</html>  